package com.syyo.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syyo.admin.domain.Column;
import com.syyo.admin.domain.Datasources;
import com.syyo.admin.domain.entity.GeneratorEntity;
import com.syyo.admin.mapper.DatasourcesMapper;
import com.syyo.admin.mapper.GeneratorMapper;
import com.syyo.admin.service.DatasourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: wangzhong
 * @Date: 2020/8/20 15:45
 * @Description:
 */
@Service
public class DatasourcesServiceImpl implements DatasourcesService {

    @Autowired
    private DatasourcesMapper datasourcesMapper;
    @Autowired
    private GeneratorMapper generatorMapper;


    @Override
    public List<Datasources> getTable() {
        List<Datasources> datasources = datasourcesMapper.findDatasources();
        for (Datasources datasource : datasources) {
            GeneratorEntity generator = generatorMapper.selectOne(new QueryWrapper<GeneratorEntity>().eq("table_name", datasource.getTableName()));
            if (generator == null) {
                datasource.setIsCfg(false);
            } else {
                datasource.setIsCfg(true);
            }
        }
        return datasources;


    }

    @Override
    public List<Column> getColumn(String tableName) {
        return datasourcesMapper.findColumn(tableName);
    }
}
